namespace NuGetGallery.Migrations
{
    using System.Data.Entity.Migrations;

    public partial class AddVulnerabilityEntities : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Cves",
                c => new
                    {
                        Key = c.Int(nullable: false, identity: true),
                        CveId = c.String(nullable: false, maxLength: 20, unicode: false),
                        Description = c.String(nullable: false, maxLength: 300),
                        LastModifiedDate = c.DateTime(nullable: false),
                        PublishedDate = c.DateTime(nullable: false),
                        Listed = c.Boolean(nullable: false),
                        Status = c.Int(nullable: false),
                        CvssRating = c.Decimal(precision: 3, scale: 1),
                    })
                .PrimaryKey(t => t.Key)
                .Index(t => t.CveId, unique: true);
            
            CreateTable(
                "dbo.Cwes",
                c => new
                    {
                        Key = c.Int(nullable: false, identity: true),
                        CweId = c.String(nullable: false, maxLength: 20, unicode: false),
                        Name = c.String(nullable: false, maxLength: 200),
                        Description = c.String(nullable: false, maxLength: 300),
                        Listed = c.Boolean(nullable: false),
                        Status = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Key)
                .Index(t => t.CweId, unique: true);
            
            CreateTable(
                "dbo.PackageDeprecationCves",
                c => new
                    {
                        PackageDeprecation_Key = c.Int(nullable: false),
                        Cve_Key = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.PackageDeprecation_Key, t.Cve_Key })
                .ForeignKey("dbo.PackageDeprecations", t => t.PackageDeprecation_Key, cascadeDelete: true)
                .ForeignKey("dbo.Cves", t => t.Cve_Key, cascadeDelete: true)
                .Index(t => t.PackageDeprecation_Key)
                .Index(t => t.Cve_Key);
            
            CreateTable(
                "dbo.PackageDeprecationCwes",
                c => new
                    {
                        PackageDeprecation_Key = c.Int(nullable: false),
                        Cwe_Key = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.PackageDeprecation_Key, t.Cwe_Key })
                .ForeignKey("dbo.PackageDeprecations", t => t.PackageDeprecation_Key, cascadeDelete: true)
                .ForeignKey("dbo.Cwes", t => t.Cwe_Key, cascadeDelete: true)
                .Index(t => t.PackageDeprecation_Key)
                .Index(t => t.Cwe_Key);
            
            DropColumn("dbo.PackageDeprecations", "CVEIds");
            DropColumn("dbo.PackageDeprecations", "CWEIds");
        }
        
        public override void Down()
        {
            AddColumn("dbo.PackageDeprecations", "CWEIds", c => c.String());
            AddColumn("dbo.PackageDeprecations", "CVEIds", c => c.String());
            DropForeignKey("dbo.PackageDeprecationCwes", "Cwe_Key", "dbo.Cwes");
            DropForeignKey("dbo.PackageDeprecationCwes", "PackageDeprecation_Key", "dbo.PackageDeprecations");
            DropForeignKey("dbo.PackageDeprecationCves", "Cve_Key", "dbo.Cves");
            DropForeignKey("dbo.PackageDeprecationCves", "PackageDeprecation_Key", "dbo.PackageDeprecations");
            DropIndex("dbo.PackageDeprecationCwes", new[] { "Cwe_Key" });
            DropIndex("dbo.PackageDeprecationCwes", new[] { "PackageDeprecation_Key" });
            DropIndex("dbo.PackageDeprecationCves", new[] { "Cve_Key" });
            DropIndex("dbo.PackageDeprecationCves", new[] { "PackageDeprecation_Key" });
            DropIndex("dbo.Cwes", new[] { "CweId" });
            DropIndex("dbo.Cves", new[] { "CveId" });
            DropTable("dbo.PackageDeprecationCwes");
            DropTable("dbo.PackageDeprecationCves");
            DropTable("dbo.Cwes");
            DropTable("dbo.Cves");
        }
    }
}
